<template>
    <nav aria-label="Page navigation example">
        <ul class="pagination">
            <li class="page-item"><a class="page-link" :href='posts.first_page_url' @click.prevent='href(1)'>首页</a></li>
            <li :key='n.id' v-for='n in item' class="page-item">
                <a class="page-link" :href='n.url' @click.prevent="href(n.number)">
                    {{ n.number }}
                </a>
            </li>
            <li class="page-item"><a class="page-link" :href='posts.last_page_url' @click.prevent='href(posts.last_page)'>尾页</a></li>
        </ul>
    </nav>
</template>

<script>
export default {
    name: 'HomePagination',
    props:['posts'],
    computed:{
        item(){
            var items = new Array();
            for (var i = 1;i <= this.posts.last_page;i++) {
                if (i == this.posts.current_page) {
                    items.push({url:false, number:i})
                } else {
                    items.push({url:'/blog?page='+i , number:i})
                }
            }
            return items
        }
    },
    methods:{
        href(num) { this.getPage(num)},
        
    },
    inject:['getPage']
}
</script>